package com.axdoc.doctor.filter;

import javax.ws.rs.container.ContainerRequestContext;
import javax.ws.rs.container.ContainerResponseContext;
import javax.ws.rs.container.ContainerResponseFilter;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response.Status;

import com.alibaba.fastjson.JSONObject;

public class CacheControlFilter implements ContainerResponseFilter {

    public void filter(ContainerRequestContext req, ContainerResponseContext res) {
        if (Status.OK.getStatusCode() == res.getStatus()) {
            Object obj = res.getEntity();
            JSONObject json = new JSONObject();
            json.put("code", Status.OK.getStatusCode());
            json.put("msg", "成功");
            json.put("result", obj);
            res.setEntity(json, null, MediaType.APPLICATION_JSON_TYPE);
        }
    }
}